package vocabularyhub.io.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import vocabularyhub.io.model.IWriter;
import vocabularyhub.word.model.IWord;


public class SimplestWriter implements IWriter {

    @Override
    public boolean writeToFile(List<IWord> words, File file)
            throws FileNotFoundException, IOException {

        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        int i = 0;
        for (Object word : words) {
            if (i++ == 1000) {
                i = 0;
                writer.flush();
            }

            writer.append(word.toString()).append(
                    System.getProperty("line.separator"));
        }
        writer.close();

        return true;
    }

}
